#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim: set ts=4 sw=4 noet:
#
# $Id$

"""
Regex Tests.
"""

__version__ = "$Revision$"
# $URL$

import os, sys, re
import py
from ..RegexEngine import RegexEngine

class Test(object):
	def setup_class(cls):
		cls._engine = RegexEngine()
	
	def test_search_complete(self):
		self._engine.setup(u"([hH]ello+) (world)", {})
		start, end = self._engine.search(u"hello world", replacePattern=u"\\2 \\1")
		assert start == 0 and end == 11 and self._engine.replacement == u"world hello"

	def test_search_incomplete(self):
		self._engine.setup(u"([hH]ello+) (world)", {})
		start, end = self._engine.search(u"blah blah hello world blah", replacePattern=u"\\2 \\1")
		assert start == 10 and end == 21 and self._engine.replacement == u"world hello"

	def test_search_metadata(self):
		self._engine.setup(u"(hello+) (world)", {re.I: True})
		start, end = self._engine.search(u"blah blah HELLOooo world blah", replacePattern=u"\\2 \\1")
		assert start == 10 and end == 24 and self._engine.replacement == u"world HELLOooo"

	def test_search_consecutiveSearches(self):
		self._engine.setup(u"([hH]ello+) (world)", {})
		start, end = self._engine.search(u"blah blah hello world blah", replacePattern=u"\\2 \\1")
		start, end = self._engine.search(u"blah blah hello world blah", replacePattern=u"\\2 \\1")
		assert start == 10 and end == 21 and self._engine.replacement == u"world hello"

# End of $URL$
